package io.renren.modules.app.service.impl;

import io.renren.common.utils.ShiroUtils;
import io.renren.modules.app.service.ShopService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import com.zheok.testing.dao.ShopDao;
import com.zheok.testing.entity.ShopEntity;
import org.springframework.util.StringUtils;


@Service("shopService")
public class ShopServiceImpl extends ServiceImpl<ShopDao, ShopEntity> implements ShopService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ShopEntity> wrapper = new QueryWrapper<>();
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        String username = userEntity.getUsername();
        if(!"admin".equals(username)){
            wrapper.lambda().eq(ShopEntity::getId,userEntity.getUserId());


        }
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.lambda().like(ShopEntity::getNikeName,key);
        }
        IPage<ShopEntity> page = this.page(
                new Query<ShopEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }

}